<?php

namespace app\daili\controller;

use think\facade\Db;

use think\facade\Request;


class Urls extends  Base

{

	public function list() {

		  $loginAdmin=session('dailiAccount'); 
		    $daili=Db::name('daili')->where('id',$loginAdmin['id'])->find();
      if($daili['yuming']==1){
            return alert('您的权限不足，请联系上级升级!','/daili/index',5,3); 
            exit;
        }
        
		$urlData=Db::name('urls')->where('uid',$loginAdmin['id'])->order('id desc')->select();
     
		return view('', [

			'urlData' => $urlData,
		
		]);

	}


 


    public function add() {
          $loginAdmin=session('dailiAccount'); 
         
		    $daili=Db::name('daili')->where('id',$loginAdmin['id'])->find();
      if($daili['yuming']==1){
            return alert('您的权限不足，请联系上级升级!','/daili/index',5,3); 
            exit;
        }
		if(request()->isPost()) {

			// 入库的逻辑

			$data = input('post.');
			unset($data['file']);
            $datas=$this->urlsadd($data['url']);
            $data['uid']=$loginAdmin['id'];
			$res = Db::name('urls')->insert($data);

			if($res){
				return alert('操作成功！','list',6,3);
			 }else{
				return alert('操作失败！','list',5,3);
			 }

		}else {

			// 获取推荐位类别

		 

			return view('', [

			

			]);

		}

	}



	//编辑广告位

	public function edit(){
 $loginAdmin=session('dailiAccount'); 
		    $daili=Db::name('daili')->where('id',$loginAdmin['id'])->find();
      if($daili['yuming']==1){
            return alert('您的权限不足，请联系上级升级!','/daili/index',5,3); 
            exit;
        }
		$id=Request::instance()->param('id');

		$adData=Db::name('urls')->find($id);


		if(request()->isPost()){
        	$datas=$this->urlsdel($adData['url']);
			$data=input('post.');
	    	$datas=$this->urlsadd($data['url']);
            $res=Db::name('urls')->where('id',$id)->update($data);

			if($res){
				return alert('操作成功！','list',6,3);
			 }else{
				return alert('操作失败！','list',5,3);
			 }

		}

		return view('', [

				'urlData'=>$adData,
			
			]);

	}



	public function del(){
	     $loginAdmin=session('dailiAccount'); 
		    $daili=Db::name('daili')->where('id',$loginAdmin['id'])->find();
      if($daili['yuming']==1){
            return alert('您的权限不足，请联系上级升级!','/daili/index',5,3); 
            exit;
        }
		$id=Request::instance()->param('id');
		$adData=Db::name('urls')->find($id);
		$datas=$this->urlsdel($adData['url']);
		$res=Db::name('urls')->where('id',$id)->delete();
		if($res){
			return alert('操作成功！','list',6,3);
		 }else{
			return alert('操作失败！','list',5,3);
		 }
	}
	





}

